package post;

/**
 *
 * CHANGE LOG;
 * DATE             MOD BY          EDITS
 * 01/30/11         Pia             created class
 * 02/01/11         Sean            added methods, cons
 */

public abstract class Payment {
    double amtPaid;  //amount customer pays
    double getAmtDue(){return amtPaid;}  //return customer payment
    abstract double makePayment(double amtPaid); //attempt to pay with amtDue
    //abstract boolean verify();  //verify that amount is correct or check/card is authenticated
    abstract double getPayment();   //return payment
    abstract String getPaymentType();
}//end Payment class

class CashPayment extends Payment{
    public CashPayment( double a )
    {
        amtPaid = a;
    }//end constructortotalCost
    /*@Override
    boolean verify()
    {
        return true;
    } //will always return true.
*/
    @Override
    double makePayment(double amtDue){
        //amtDue -= amountPaid;   //subtract
        return amtDue - amtPaid;
    }//end makePayment
    public double getPayment()
    {
        return amtPaid;
    }
    @Override
    String getPaymentType()
    {
        return "CASH";
    }
}//end CashPayment

class CheckPayment extends Payment {
    public CheckPayment( double a )
    {
        amtPaid = a;
    }
    boolean verify(){
        if (Math.random() <= 0.10 ) return false;   //reject at 10%
        else return true;
    }

    @Override
    double makePayment(double amountPaid){
        return 0;   //assume checks are exact
    }
    @Override
    public double getPayment()
    {
        if( verify() )
            return amtPaid;
        else
            return -1;
    }
    @Override
    String getPaymentType()
    {
        return "Paid by Check";
    }
}//end CheckPayment

class CreditPayment extends Payment{
    private int cardNum;
    public CreditPayment( int c )
    {
        cardNum = c;
    }
    boolean verify(){
        if (Math.random() <= 0.10 ) return false;   //reject at 10%
        else return true;                           //approve 90%
    }

    @Override
    double makePayment(double amountPaid){
         if (verify()){
            return 0; }
        else return -1;
    }
    public double getPayment()
    {
        return amtPaid;
    }
    @Override
    String getPaymentType()
    {
        return "Paid by Credit Card " + cardNum;
    }
}//end CreditPayment
